Skip to content

gh-146632: make traceback handle illformed ModuleNotFoundError#146633

Open
Locked-chess-official wants to merge 3 commits intopython:mainfrom
Locked-chess-official:fix_crash_in_traceback
Open

gh-146632: make traceback handle illformed ModuleNotFoundError#146633
Locked-chess-official wants to merge 3 commits intopython:mainfrom
Locked-chess-official:fix_crash_in_traceback

Conversation

@Locked-chess-official
Copy link
Copy Markdown
Contributor

@Locked-chess-official Locked-chess-official commented Mar 30, 2026

@Shrey-N
Copy link
Copy Markdown
Contributor

Shrey-N commented Mar 30, 2026

Hiya @Locked-chess-official, Shouldn't we add a regression test for this in Lib/test/test_traceback.py that uses ModuleNotFoundError(name=NotImplemented)?

btw the CI failure is an unrelated issue.

Great fix :)

@serhiy-storchaka serhiy-storchaka requested a review from FFY00 March 30, 2026 17:29
if entry.name.startswith(child + '.') and entry.name.endswith(untagged_suffix):
return entry.name
except Exception:
return
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring silently exceptions sounds like a bad pattern. If you expect specific exceptions, use more precise except.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is impossible to use precise except. It is in handling an exception, where raising another exception will cause the crash.

Copy link
Copy Markdown
Member

@picnixz picnixz Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I sugegst that we let the exception propagate. If this code path fails it's something we want to know.

import importlib.machinery
import importlib.resources.readers

if not module_name or not importlib.machinery.EXTENSION_SUFFIXES:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep not module_name test.

@picnixz picnixz changed the title gh-146632: Fix crash in traceback gh-146632: make traceback handle illformed ModuleNotFoundError Mar 30, 2026
if entry.name.startswith(child + '.') and entry.name.endswith(untagged_suffix):
return entry.name
except Exception:
return
Copy link
Copy Markdown
Member

@picnixz picnixz Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I sugegst that we let the exception propagate. If this code path fails it's something we want to know.

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Mar 30, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants